package com.linyx.simpleboot.service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
 
public class AnalysisXmlUtils {
 
 /**
  * 
  * @Title: queryXmlData 
  * @Description: 将xml标签中的数据读取出来
  * @param @param xml
  * @param @param element
  * @param @return    入参
  * @return String    返回类型
  * @author 
  * @throws
  * @date 2019年6月21日 下午4:57:02 
  * @version V1.0   
  */
 public static Map<String, Object> queryXmlData(String xml) {
  Map<String, Object> map = new HashMap<String, Object>();
  try {
//   Document doc = DocumentHelper.parseText(xml);

	
	SAXReader reader =new SAXReader();
	Document document=reader.read("E:\\Git\\myspringboot\\myspringboot\\target\\classes\\mapper\\UserMapper2.xml");
   
   Element root = document.getRootElement();
   
   List<Element> list = root.elements("select");
   
   if(list != null && !list.isEmpty()) {
    for (Element element : list) {
    	
    	System.out.println(element.getText());
//     map.put(element.element("key").getText(), new String[] {element.elementText("name"),element.elementText("seq")});
    }
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return map;
 }
 
// public static void main(String[] args) {
//  String value ="<root><param><name>告警级别</name><key>severity</key><seq>：</seq></param><param><name>事件状态</name><key>event_status</key><seq>：</seq></param><param><name>主机群组</name><key>host_group</key><seq>：</seq></param><param><name>主机名称</name><key>host_name</key><seq>：</seq></param><param><name>监控项名称</name><key>item_name</key><seq>：</seq></param><param><name>监控项值</name><key>item_value</key><seq>：</seq></param><param><name>主机ip地址</name><key>host_ip</key><seq>：</seq></param><param><name>告警内容</name><key>trigger_name</key><seq>：</seq></param><param><name>事件时间</name><key>event_time</key><seq>：</seq></param><param><name>监控对象</name><key>item_key</key><seq>：</seq></param><param><name>事件id</name><key>event_id</key><seq>：</seq></param><param><name>平台来源</name><key>source</key><seq>：</seq></param></root>";
//  Map<String, Object> map = queryXmlData(value);
//  System.out.println(map.toString());
// }
 
}